<script setup lang="ts">
import router from '@/router'
import { ref, computed, onBeforeMount } from 'vue'
import type { BriefProject } from '@/types/ProjectType'
import { api } from '@/api/api'

function toInfo(_id: number) {
  router.push({
    name: 'infoQ',
    params: { id: _id }
  })
}

var tableData = ref<BriefProject[]>([])
const allTableData = ref<BriefProject[]>([])

onBeforeMount(() => {
  api.getConfirmingProject().then((resp) => {
    allTableData.value = resp
    count = allTableData.value.length
  })
  tableData = computed(() => {
    let result = allTableData.value.slice(
      (currentPage.value - 1) * currentSize.value,
      currentPage.value * currentSize.value
    )
    return result
  })
})
const currentPage = ref(1)
const currentSize = ref(10)
var count: number
count = allTableData.value.length

const currentChange = (page: number) => {
  currentPage.value = page
}

const sizeChange = (size: number) => {
  currentSize.value = size
}
</script>

<template>
  <div class="main">
    <h1 class="h1">未确认项目</h1>
    <div class="listbox">
      <div class="number">
        <h3>共计{{ count }}条项目</h3>
      </div>
      <el-table :data="tableData" stripe style="width: 100%">
        <el-table-column type="index" label="序号" width="150" />
        <el-table-column prop="id" label="编号" width="150" />
        <el-table-column prop="name" label="名称" width="300" />
        <el-table-column prop="creator_name" label="发起人" width="150" />
        <el-table-column label=" " width="100">
          <template #default="scope">
            <el-button link type="primary" size="small" @click="toInfo(scope.row.id)"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
  <div class="pager">
    <el-pagination
      @size-change="sizeChange"
      @current-change="currentChange"
      :current-page="currentPage"
      :page-size="currentSize"
      :background="true"
      layout="prev, pager, next, jumper"
      :total="count"
      :hide-on-single-page="true"
    />
  </div>
</template>

<style scoped>
.main {
  width: 100%;

  .h1 {
    margin-left: 50px;
    margin-top: 50px;
  }
}

.createtag {
  float: right;
  margin-top: 100px;
}

.listbox {
  margin-top: 100px;
  margin-left: 100px;
  margin-right: 100px;
  padding-left: 20px;
  padding-right: 20px;
}

.pager {
  margin-left: 100px;
  margin-top: 50px;
}
</style>
